

			
			
**************************************************************
* I. DATA PREAMBLE FOR MAIN TABLES
************************************************************** 
capture program drop data_preamble

program  data_preamble, nclass
	

		set more off 
		drop if education_level==4 //Dropping missing education
		xtset ctry education_level
		*keep if  pew_muslims_pct>50 & pew_muslims_pct!=. //majority muslim
	
		*Take logs, create rescaled variables
			foreach v in pop_tot pop_muslim_pew gdp_pc dist_tosyria political_rights corruption_index {
				*g      log_`v'      =ln(`v')
				g      a`v'         =`v' if nisis_educ!=0 
				egen   m3`v'        =mean(a`v')
				g      resc3_log_`v'=ln(`v') -ln(m3`v')
				g      resc3_`v'    =`v'- m3`v'

			}	
			
		*Creating new rescaled variables
			foreach v in log_pop_tot log_pop_muslim_pew log_gdp_pc political_rights corruption_index {
			g resc_`v'=resc3_`v'
			}

		*Labeling of key variables 
			la var log_pop_tot        "Total population (log)"
			la var log_gdp_pc         "Per capita GDP (log)"
			la var frac_muslim        "Muslim fraction"
			la var log_pop_muslim_pew "Muslim population (log)"
			la var log_dist_tosyria   "Distance to Syria (log)"
			la var political_rights   "Index of political rights"
			la var corruption_index   "Corruption Index"
			la var log_ilo2_pop       "Total Labor Force (log)"
			la var ilo2_unemp_educ    "Unemployment rate"
			la var ctry				  "countries"
	       
		*Main interactions of UE with stuff that we use in regs
			gen unemp_secondary               =ilo2_unemp_educ*educ2
			gen unemp_tertiary                =ilo2_unemp_educ*educ3
			gen unemp_loggdp             	  =ilo2_unemp_educ*log_gdp_pc
			gen unemp_logdistance	          =ilo2_unemp_educ*log_dist_tosyria		
			gen unemp_frac_muslim             =ilo2_unemp_educ*frac_muslim
			gen unemp_logdistance_loggdp	  =ilo2_unemp_educ*log_dist_tosyria*log_gdp_pc	// triple interaction not used 
		
		*Interactions of UE with rescaled variables, not used in the end
			gen unemp_resc_loggdp             =ilo2_unemp_educ*resc_log_gdp_pc
			gen unemp_resc_logmuslimpop       =ilo2_unemp_educ*resc_log_pop_muslim_pew
			gen unemp_resc_logpop_tot         =ilo2_unemp_educ*resc_log_pop_tot
			gen unemp_resc_politicalrts       =ilo2_unemp_educ*resc_political_rights
			gen unemp_resc_corruption         =ilo2_unemp_educ*resc_corruption_index
		
		*Interactions of UE with region dummies
			gen unemp_reg_mena				  =ilo2_unemp_educ*reg_mena
			gen unemp_reg_officialoecd		  =ilo2_unemp_educ*reg_officialoecd
			gen unemp_reg_europe			  =ilo2_unemp_educ*g_region_europe
			gen unemp_reg_formersoviet		  =ilo2_unemp_educ*g_region_formersoviet
			gen unemp_reg_asia			  	  =ilo2_unemp_educ*g_region_asia
			gen unemp_reg_americas			  =ilo2_unemp_educ*g_region_americas
			gen unemp_reg_subafrica			  =ilo2_unemp_educ*g_region_subafrica

		*Interactions for additional horse-races added after JEEA comments
			replace fragment=1 if fragment==2 | fragment==3
			foreach v in fraction_ethnic fraction_language fraction_religion dpi_gf political_rights corruption_index /// 
						I_SOCREG I_GVTREG I_GVTFAV GFI_AG soc_rel_regulation gov_rel_regulation ///
						polity2 fragment { 
			gen unemp_`v'=ilo2_unemp_educ*`v'	
						}
				// potentially to add later: any other vars we use as controls, polity, democracies vs autocracies
		
		*Labeling of interacted variables	
			la var unemp_secondary               "Secondary education"
			la var unemp_tertiary                "Tertiary education"
			la var unemp_logdistance             "Distance to Syria (log)"
			la var unemp_loggdp         		 "Per capita GDP (log)"		
			la var unemp_logdistance_loggdp      "Distance to Syria (log) * Per capita GDP (log)"		
			la var unemp_frac_muslim             "Muslim fraction"
			la var unemp_resc_loggdp             "Per capita GDP (log)"
			la var unemp_resc_logmuslimpop       "Muslim population (log)"
			la var unemp_resc_logpop_tot         "Total population (log)"
			la var unemp_resc_politicalrts       "Index of political rights"
			la var unemp_resc_corruption         "Corruption Index"
			la var unemp_reg_mena           	 "MENA region dummy"
			la var unemp_reg_officialoecd   	 "Official OECD region dummy"
			la var unemp_reg_europe         	 "Europe"
			la var unemp_reg_formersoviet		 "Former Soviet"
			la var unemp_reg_asia	 			 "Asia"
			la var unemp_reg_americas	  		 "Americas"
			la var unemp_reg_subafrica	  		 "Sub- Saharan Africa"
			
		*Labeling of additional interaction variables
			la var unemp_fraction_ethnic         "Ethnic fractionalization"
			la var unemp_fraction_language       "Linguistic fractionalization"
			la var unemp_fraction_religion       "Religious fractionalization"
			la var unemp_dpi_gf                  "Government fractionalization"
			la var unemp_political_rights        "Political rights"
			la var unemp_corruption_index        "Corruption index"
			la var unemp_polity2	             "Polity index"
			la var unemp_fragment               "Political fragmentation (dummy)"
			la var unemp_soc_rel_regulation      "Social regulation of religion"
			la var unemp_gov_rel_regulation      "Government regulation of religion"

		cap drop median_dist tercile_dist quart_dist // Removing unconditional splits
		
		//Merging in quantile splits
		cap drop _merge
		merge m:1 ctry using "${outdir}/quartile_split.dta"

		
		*Labeling quartile variables
			local varintlist="mnp mdp minp maxp xdist xmnp xmdp xminp xmaxp"

			foreach v in `varintlist' {
				gen unemp_log_`v'				 =ilo2_unemp_educ*ln(`v')
				la var unemp_log_`v'				 "Travel Cost to Syria (log)"				
			}
			
			foreach v in `varintlist' dist {
				
				gen unemp_median_`v'1         	=ilo2_unemp_educ*median_`v'1
				gen unemp_median_`v'2         	=ilo2_unemp_educ*median_`v'2
				gen unemp_tercile_`v'1         =ilo2_unemp_educ*tercile_`v'1
				gen unemp_tercile_`v'2         =ilo2_unemp_educ*tercile_`v'2
				gen unemp_tercile_`v'3         =ilo2_unemp_educ*tercile_`v'3
				gen unemp_quart_`v'1           =ilo2_unemp_educ*quart_`v'1
				gen unemp_quart_`v'2           =ilo2_unemp_educ*quart_`v'2
				gen unemp_quart_`v'3           =ilo2_unemp_educ*quart_`v'3
				gen unemp_quart_`v'4           =ilo2_unemp_educ*quart_`v'4
			}
		
				la var unemp_median_dist1         	 "Distance to Syria - First Half"
				la var unemp_median_dist2         	 "Distance to Syria - Second Half"
				la var unemp_tercile_dist1         	 "Distance to Syria - First Tercile"
				la var unemp_tercile_dist2         	 "Distance to Syria - Second Tercile"
				la var unemp_tercile_dist3         	 "Distance to Syria - Third Tercile"
				la var unemp_quart_dist1         	 "Distance to Syria - First Quartile"
				la var unemp_quart_dist2         	 "Distance to Syria - Second Quartile"
				la var unemp_quart_dist3         	 "Distance to Syria - Third Quartile"
				la var unemp_quart_dist4         	 "Distance to Syria - Fourth Quartile"
			
			foreach v in `varintlist' {
				la var unemp_median_`v'1         	 "Travel Cost to Syria - First Half"
				la var unemp_median_`v'2         	 "Travel Cost to Syria - Second Half"
				la var unemp_tercile_`v'1         	 "Travel Cost to Syria - First Tercile"
				la var unemp_tercile_`v'2         	 "Travel Cost to Syria - Second Tercile"
				la var unemp_tercile_`v'3         	 "Travel Cost to Syria - Third Tercile"
				la var unemp_quart_`v'1         	 "Travel Cost to Syria - First Quartile"
				la var unemp_quart_`v'2         	 "Travel Cost to Syria - Second Quartile"
				la var unemp_quart_`v'3         	 "Travel Cost to Syria - Third Quartile"
				la var unemp_quart_`v'4         	 "Travel Cost to Syria - Fourth Quartile"		
			}
		
	*Create median dummies for subsample tables
		
			foreach v in fraction_ethnic fraction_language fraction_religion /* dpi_gf  */ political_rights corruption_index /// 
						I_SOCREG I_GVTREG I_GVTFAV GFI_AG soc_rel_regulation gov_rel_regulation ///
						polity2 fragment ///
						log_gdp_pc { 
				
				xtreg logn_educ ilo2_unemp_educ log_ilo2_pop unemp_logdistance educ2 educ3 ctrydummy*, fe vce(cluster ctry)  
				xtile median_`v' = `v' if e(sample), nq(2)
				
				}

				
		*Sample split dummies for triple interaction tables 		
			g amed_muslim =(median_frac_muslim==2) 
			g majority_muslim = (pew_muslims_pct>50 & pew_muslims_pct!=.)
			g amed_gdp=(median_log_gdp_pc==2)
		
		
		*Interactions with median dummies for triple interaction table 
			foreach v in amed_muslim majority_muslim amed_gdp { 
			gen unemp_`v'=ilo2_unemp_educ*`v'	
						}		
			foreach v in amed_muslim majority_muslim amed_gdp reg_mena reg_officialoecd { 
			gen dunemp_`v'=ilo2_unemp_educ*log_dist_tosyria*`v'		
			gen l_`v'=log_ilo2_pop*`v'
						}							
		
		*Labels for variables for triple interaction table
			la var unemp_amed_muslim "Muslim $>$ 50%" 
			la var unemp_majority_muslim "Muslim Majority"
			la var unemp_amed_gdp "Above-Median GPDpc"
			la var dunemp_amed_muslim "Distance * Muslim $>$50%"
			la var dunemp_majority_muslim "Distance * Muslim Majority"
			la var dunemp_amed_gdp "Distance * Above-Median GDPpc"
			la var dunemp_reg_mena           	 "Distance * MENA"
			la var dunemp_reg_officialoecd   	 "Distance * OECD"		
			
						
		cd "$outdir"				
end
		
			
			
